﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CompanyBussiness;

namespace Website.customer.Control
{
    public partial class cCategoryContent : System.Web.UI.UserControl
    {
        HtmlMeta metaTag;
        NewsManagement newsMana = new NewsManagement();
        LanguagesManagement languageMana = new LanguagesManagement();
        CompanyBussiness.Category category = new Category();
        CompanyBussiness.Language language;
        Metadata meta;
        int IDS;
        string modulCode;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request[CONST.QUERYSTRING_CATEGORY] == null)
                {
                    //quay ve trang home
                    Response.Redirect("~/Hem.html");
                }
                else
                {
                    LoadContent();
                }
            }
        }
        protected void LoadContent()
        {
            try
            {
                modulCode = Request.QueryString["Mod"];

                IDS = int.Parse(Request[CONST.QUERYSTRING_CATEGORY].ToString());
                category = newsMana.GetCategoryByID(IDS,modulCode);

                lbCategoryName.Text = category.CategoryName.ToString();
                if (category.CategoryImg != string.Empty)
                {
                    imgCategory.ImageUrl = category.CategoryImg.ToString().Replace("img_", "larger_");
                    imgCategory.ToolTip = category.CategoryName;
                }
                else
                {
                    imgCategory.Visible = false;
                    imgCategory.Style.Add("display", "none");
                }
                    

                if (category.ImagesStatus == false)
                {
                    imgCategory.Visible = false;
                }
                else
                    imgCategory.Visible = true;
                
                lbCategoryIntro.Text = category.CategoryIntro.ToString();
                litCategoryContent.Text = category.CategoryDes;

                meta = newsMana.GetMetadataByCategoryID(IDS);
                if (meta != null)
                {
                    //ghi metadata
                    metaTag = new HtmlMeta();
                    metaTag.Name = "keywords";
                    metaTag.Content = meta.MetaKeyword;
                    Page.Header.Controls.Add(metaTag);

                    metaTag = new HtmlMeta();
                    metaTag.Name = "description";
                    metaTag.Content = meta.MetaDesciption;
                    Page.Header.Controls.Add(metaTag);

                    Page.Header.Title = meta.Title;
                }
                


            }
            catch (Exception)
            {

            }
        }
    }
}